package com.sxt.bus.service.impl;

import com.sxt.bus.domain.ChargeRule;
import com.sxt.bus.domain.ChargeRuleKey;
import com.sxt.bus.mapper.ChargeRuleMapper;
import com.sxt.bus.service.ChargeRuleService;
import com.sxt.bus.vo.ChargeRuleVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author WanMing
 * @date 2019/2/10 20:22
 */

@Service
public class ChargeRuleServiceImpl implements ChargeRuleService {

    @Autowired
    private ChargeRuleMapper chargeRuleMapper;

    /**
     * 修改业务
     *
     * @param chargeRuleVo
     */
    @Override
    public void updateChargeRule(ChargeRuleVo chargeRuleVo) {
        String funcId = chargeRuleVo.getFuncId();
        //先删除
        String[] chargeKeyCodes = chargeRuleVo.getChargeCode().split(",");

            ChargeRuleKey chargeKeyRule = new ChargeRuleKey();
            chargeKeyRule.setFuncId(funcId);

            chargeRuleMapper.deleteByPrimaryKey(chargeKeyRule);


        //再添加

        for (String chargeCode : chargeKeyCodes) {
            ChargeRule chargeRule = new ChargeRule();
            chargeRule.setFuncId(funcId);
            chargeRule.setChargeCode(chargeCode);
            chargeRule.setFuncName(chargeRuleVo.getFuncName());
            chargeRuleMapper.insertSelective(chargeRule);
        }

    }

    /**
     * 查询所有
     *
     * @param chargeRuleVo
     * @return
     */
    @Override
    public List<ChargeRule> queryAllChargeRule(ChargeRuleVo chargeRuleVo) {

        return chargeRuleMapper.queryAllChargeRule(chargeRuleVo);
    }
}
